package com.zkingsoft.rhi.handler;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;


/**
 * @author xieguo
 * @since 2020/11/4 11:24
 */



public class Result {


    private static volatile Consequence consequence=new Consequence();

    /**
     * code结果状态码 0:操作成功；
     */
    public static int STATUS_SUCCESS=0;//成功
    public static int STATUS_FAIL=1;//失败
    public static int VALIDATION_FAILED=3;//未登录，或者登录过期
    public static int SYSTEM_EXCEPTION=4;//4:系统异常




    public static JSONObject defeatedResultByMsg(String msg){
        consequence.clear();
        consequence.setCode(SYSTEM_EXCEPTION);
        consequence.setDate("");
        consequence.setMsg("系统异常，请联系管理员");
        consequence.setDevMsg(msg);
        return getResult(consequence);
    }


    public static JSONObject setResultByCodeAndMsg(Integer code,String msg){
        consequence.clear();
        consequence.setCode(code);
        consequence.setMsg(msg);
        return getResult(consequence);
    }

    public static JSONObject setResultByCodeAndMsgAndDate(Integer code,String msg, Object date,Integer count){
        consequence.clear();
        consequence.setCode(code);
        consequence.setDate(date);
        consequence.setMsg(msg);
        consequence.setCount(count);
        return getResult(consequence);
    }


    private static JSONObject getResult(Consequence consequence){
        return (JSONObject) JSON.toJSON(consequence);
    }


}

